package com.WuZiQi;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GameFrame extends JFrame implements ActionListener {
    private GamePanel gamePanel;
    public GameFrame() {
        Font font = new Font("微软雅黑", Font.BOLD, 12);
//窗口
        JMenuBar menuBar = new JMenuBar();
        JMenu menu1 = new JMenu("游戏");
        menu1.setFont(font);

        JMenuItem menu1_item1=menu1.add("开始游戏");
        JMenuItem menu1_item2=menu1.add("悔棋");
        JMenuItem menu1_item3=menu1.add("认输");
        menu1.addSeparator();
        JMenuItem menu1_item4=menu1.add("退出游戏");

        JMenu menu2 = new JMenu("帮助");
        menu2.setFont(font);
        JMenuItem menu2_item1=menu2.add("关于");

        menuBar.add(menu1);
        menuBar.add(menu2);
        this.setJMenuBar(menuBar);

        this.setTitle("五子棋");
        this.setSize(Const.window_width, Const.window_height);
        this.setLocationRelativeTo(null);
        this.setResizable(false);


        menu1_item1.setActionCommand("new");
        menu1_item1.addActionListener(this);
        menu1_item2.setActionCommand("undo");
        menu1_item2.addActionListener(this);
        menu1_item3.setActionCommand("surrender");
        menu1_item3.addActionListener(this);
        menu1_item4.setActionCommand("exit");
        menu1_item4.addActionListener(this);
        menu2_item1.setActionCommand("about");
        menu2_item1.addActionListener(this);

        this.gamePanel = new GamePanel();
        this.add(gamePanel);

        this.setVisible(true);
    }
        public void actionPerformed(ActionEvent e){
        String command=e.getActionCommand();
            switch (command){
                case "new":
                    JOptionPane.showMessageDialog(this, "游戏开始");
                    break;
                case "undo":
                    JOptionPane.showMessageDialog(this, "晦气");
                    break;
                case "surrender":
                    int r =JOptionPane.showConfirmDialog(this, "认输，你输了?", "提示", JOptionPane.OK_CANCEL_OPTION);
                    System.out.println(r);
                    break;
                case "exit":
                    System.exit(0);
                case "about":
                    JOptionPane.showMessageDialog(this, "关于");
                    break;
                default:
                    JOptionPane.showMessageDialog(this, "未知命令");

            }
        }

}
